package com.newworld.dmsapp2.activity;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.newworld.dmsapp2.BaseActivity;
import com.newworld.dmsapp2.R;
import com.newworld.dmsapp2.activity.designtask.AssignAndReassignTaskActivity;
import com.newworld.dmsapp2.activity.serviceapply.ChoosephotoActivity;
import com.newworld.dmsapp2.activity.serviceapply.SoundActivity;
import com.newworld.dmsapp2.activity.serviceapply.ViewPagerActivity;
import com.newworld.dmsapp2.activity.visit.VisitDetailActivity;
import com.newworld.dmsapp2.bean.Task;
import com.newworld.dmsapp2.bean.User;
import com.newworld.dmsapp2.ui.view.BadgeView;
import com.newworld.dmsapp2.ui.view.CustomDialog;
import com.newworld.dmsapp2.ui.view.CustomLoadingDialog;
import com.newworld.dmsapp2.util.Config;
import com.newworld.dmsapp2.util.HttpUtil;
import com.newworld.dmsapp2.util.SingleSample;
import com.newworld.dmsapp2.util.Tool;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

public class ServiceScheduleAccomplishActivity extends BaseActivity implements
		OnClickListener {
	@SuppressWarnings("unused")
	private TextView accomplish_tasknum, accomplish_address, accomplish_object,
			accomplish_repairtime, accomplish_username, accomplish_telephone,
			accomplish_repairdescribe,
			accomplish_servicetime, accomplish_serviceman,report_location,
			accomplish_servicetelephone, reportVoiceTime, serviceVoiceTime;
	private ImageView repoertvoice, repairimage1, repairimage2, servicevoice,
			serviceimage1, serviceimage2;
	private EditText accomplish_servicedescribe;
	private Intent intent;
	private Bundle bundle;
	private LinearLayout guideTimeLineLl;
	private Button submitBtn, pushBtn, stopBtn;
	private TextView saveBtn;
	private TextView titleCenterTv;
	private LinearLayout leftLinLayout;
	private ProgressBar loginbar;
	private CustomLoadingDialog uploadingdialog;
	private User user;
	
	private String functioncode;
	private String taskstate;
	private String solveimagePath1 = "";
	private String solveimagePath2 = "";
	private String reportimagePath1 = "";
	private String reportimagePath2 = "";
	private String solvevoicePath = "";
	private String reportvoicePath = "";
	private String imageRealPath1 = "";
	private String imageRealPath2 = "";
	private String message = "";
	private BadgeView badgeImage1;
	private BadgeView badgeImage2;
	private BadgeView badgeVoice;
	private String areaname;
	private String repairId;
	private String houseFullName;
	private String sessionId;
	private Task task;
	private int voiceTime;
	private Uri imageUri;
	private String realfunctioncode;
	private String areaType;
	private String peopleType;
	private boolean isReporter;


	public static int flag = 0;

	Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			switch (msg.what) {
			case Config.HANDLER_MSG_SUCCESS:
				accomplish_tasknum.setText(task.getRepairNum());
				accomplish_address.setText(houseFullName);
				// 维修区域信息拼接
				areaname = Tool.getHouseType(task);
				accomplish_object.setText(areaname + "/"
						+ task.getRepairObject());
				if (null != task.getReportTime()
						&& !task.getReportTime().equals("")) {
					if (task.getReportTime().length() > Config.TIMELENGTH) {
						accomplish_repairtime.setText(task.getReportTime()
								.substring(0, Config.TIMELENGTH));
					} else {
						accomplish_repairtime.setText(task.getReportTime());
					}
				}

				if (null != task.getRepairTime()
						&& !task.getRepairTime().equals("")) {
					Log.e("task.getRepairTime().length()---111>", task
							.getRepairTime().length() + "");
					if (task.getRepairTime().length() > Config.TIMELENGTH) {
						Log.e("task.getRepairTime().length()---222>", task
								.getRepairTime().length() + "");
						accomplish_servicetime.setText(task.getRepairTime()
								.substring(0, Config.TIMELENGTH));
					} else {
						accomplish_servicetime.setText(task.getRepairTime());
					}
				}
				accomplish_username.setText(task.getReporter_realName());
				accomplish_repairdescribe.setText(task.getProblemDescript());
				accomplish_serviceman.setText(task.getServer_realName());
				accomplish_telephone.setText(task.getReporter_phone());
				accomplish_servicetelephone.setText(task
						.getServer_mobilePhone());
				if (functioncode.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST)
						|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER)&& isReporter)
						&& (taskstate.equals(Config.TASKSTATE_TODO) 
								|| taskstate.equals(Config.TASKSTATE_DOING) 
								|| taskstate.equals(Config.TASKSTATE_TOPOST)
								|| taskstate.equals(Config.TASKSTATE_BEASKED))) {// 维修任务
					
						accomplish_servicedescribe.setEnabled(true);
						if (null == task.getSolvedDescript()
								|| task.getSolvedDescript().equals("")) {
							accomplish_servicedescribe.setHint("请输入维修描述");
							accomplish_servicedescribe.setText(task
									.getSolvedDescript());

						} else {
							accomplish_servicedescribe.setText(task
									.getSolvedDescript());
						}
					
				} else {
					accomplish_servicedescribe.setEnabled(false);
					if (null == task.getSolvedDescript()
							|| task.getSolvedDescript().equals("")) {
						accomplish_servicedescribe.setText("");

					} else {
						accomplish_servicedescribe.setText(task
								.getSolvedDescript());
					}

				}

				if (functioncode.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST)
						|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER)&& isReporter)
						&& (taskstate.equals(Config.TASKSTATE_TODO) 
								|| taskstate.equals(Config.TASKSTATE_DOING) 
								|| taskstate.equals(Config.TASKSTATE_TOPOST)
								|| taskstate.equals(Config.TASKSTATE_BEASKED))) {// 维修任务

					if (!solveimagePath1.equals("")) {
						badgeImage1.setText("  ");
						badgeImage1.setTextSize(12);
						badgeImage1
								.setBackgroundResource(R.drawable.badge_view);
						badgeImage1
								.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
						badgeImage1.setBadgeMargin(0, 0);
						badgeImage1.toggle();
						badgeImage1.show();
						badgeImage1.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View v) {
								imageRealPath1 = imageRealPath2;
								solveimagePath1 = solveimagePath2;
								solveimagePath2 = "";
								imageRealPath2 = "";

								if (solveimagePath1.equals("")) {
									badgeImage1.hide();
									ImageLoader.getInstance().displayImage(
											null, serviceimage1, options);

									serviceimage2.setVisibility(View.INVISIBLE);
								} else {
									badgeImage2.hide();
									ImageLoader.getInstance().displayImage(
											"file://" + Config.IMAGE_PATH
													+ solveimagePath1,
											serviceimage1, options);
									ImageLoader.getInstance().displayImage(
											null, serviceimage2, options);
								}
							}
						});
						ImageLoader.getInstance()
								.displayImage(
										"file://" + Config.IMAGE_PATH
												+ solveimagePath1,
										serviceimage1, options);
						getResources()
								.getDrawable(
										R.drawable.defect_compose_pic_add_highlighted);
						serviceimage2.setVisibility(View.VISIBLE);
					}
					if (!solveimagePath2.equals("")) {
						badgeImage2.setText("  ");
						badgeImage2.setTextSize(12);
						badgeImage2
								.setBackgroundResource(R.drawable.badge_view);
						badgeImage2
								.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
						badgeImage2.setBadgeMargin(0, 0);
						badgeImage2.toggle();
						badgeImage2.show();
						badgeImage2.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View v) {
								// TODO Auto-generated method stub
								solveimagePath2 = "";
								imageRealPath2 = "";
								badgeImage2.hide();
								ImageLoader.getInstance().displayImage(null,
										serviceimage2, options);

							}
						});
						ImageLoader.getInstance()
								.displayImage(
										"file://" + Config.IMAGE_PATH
												+ solveimagePath2,
										serviceimage2, options);
					}

					if (!solvevoicePath.equals("")) {
						badgeVoice.setText("  ");
						badgeVoice.setTextSize(12);
						badgeVoice
								.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
						badgeVoice.setBackgroundResource(R.drawable.badge_view);
						badgeVoice.setBadgeMargin(0, 0);
						badgeVoice.toggle();
						badgeVoice.show();
						badgeVoice.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View v) {
								// TODO Auto-generated method stub

								badgeVoice.hide();
								solvevoicePath = "";
								serviceVoiceTime.setVisibility(View.INVISIBLE);

							}
						});

						serviceVoiceTime.setVisibility(View.VISIBLE);
						serviceVoiceTime.setText(voiceTime + "'");
					}
				} else {
					if (null != task.getProblemImage1()
							&& !task.getProblemImage1().equals("")) {
						reportimagePath1 = task.getProblemImage1();
						repairimage1.setVisibility(View.VISIBLE);
						ImageLoader.getInstance().displayImage(
								"file://" + Config.IMAGE_PATH
										+ task.getProblemImage1(),
								repairimage1, options);
					} else {
						repairimage1.setVisibility(View.INVISIBLE);
					}
					if (null != task.getProblemImage2()
							&& !task.getProblemImage2().equals("")) {
						reportimagePath2 = task.getProblemImage2();
						repairimage2.setVisibility(View.VISIBLE);
						ImageLoader.getInstance().displayImage(
								"file://" + Config.IMAGE_PATH
										+ task.getProblemImage2(),
								repairimage2, options);
					} else {
						repairimage2.setVisibility(View.INVISIBLE);
					}
					if (null != task.getProblemVoice()
							&& !task.getProblemVoice().equals("")) {
						int voicetime = Tool.voiceTime(ServiceScheduleAccomplishActivity.this,Config.VOICE_PATH+task.getProblemVoice());
						int realvoicetime = (int) voicetime/1000;
						reportvoicePath = task.getProblemVoice();
						repoertvoice.setVisibility(View.VISIBLE);
						reportVoiceTime.setVisibility(View.VISIBLE);
						reportVoiceTime.setText(realvoicetime+"'");
						//assign_repair_voice.setVisibility(View.VISIBLE);
						Log.e("realvoicetime", realvoicetime+"'");
						
					} else {
						repoertvoice.setVisibility(View.INVISIBLE);
						reportVoiceTime.setVisibility(View.INVISIBLE);
					}
					if (null != task.getSolvedImage1()
							&& !task.getSolvedImage1().equals("")) {
						solveimagePath1 = task.getSolvedImage1();
						serviceimage1.setVisibility(View.VISIBLE);
						ImageLoader.getInstance().displayImage(
								"file://" + Config.IMAGE_PATH
										+ task.getSolvedImage1(),
								serviceimage1, options);
					} else {
						serviceimage1.setVisibility(View.INVISIBLE);
					}
					if (null != task.getSolvedImage2()
							&& !task.getSolvedImage2().equals("")) {
						solveimagePath2 = task.getSolvedImage2();
						serviceimage2.setVisibility(View.VISIBLE);
						ImageLoader.getInstance().displayImage(
								"file://" + Config.IMAGE_PATH
										+ task.getSolvedImage2(),
								serviceimage2, options);
					} else {
						serviceimage2.setVisibility(View.INVISIBLE);
					}
					if (null != task.getSolvedVoice()
							&& !task.getSolvedVoice().equals("")) {
						int voicetime = Tool.voiceTime(ServiceScheduleAccomplishActivity.this,Config.VOICE_PATH+task.getSolvedVoice());
						int realvoicetime = (int) voicetime/1000;

						
						solvevoicePath = task.getSolvedVoice();
						servicevoice.setVisibility(View.VISIBLE);
						servicevoice
								.setBackgroundResource(R.drawable.defect_voice);
						serviceVoiceTime.setVisibility(View.VISIBLE);
						serviceVoiceTime.setText(realvoicetime+"'");
						Log.e("realvoicetime", realvoicetime+"'");
						
					} else {
						servicevoice.setVisibility(View.INVISIBLE);
						serviceVoiceTime.setVisibility(View.INVISIBLE);
					}
				}
				Toast.makeText(ServiceScheduleAccomplishActivity.this,
						(String) msg.obj, Toast.LENGTH_SHORT);
				loginbar.setVisibility(View.INVISIBLE);
				break;
			case Config.HANDLER_MSG_FAIL_1:
				Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
						"json连接失败",uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_FAIL_2:
				Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
						"json解析出错",uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_REPAIR_COMPELETE_SUCCESS:
				Tool.judgedialog(ServiceScheduleAccomplishActivity.this, "完成维修",
						uploadingdialog, loginbar);
				if(user.isTaskExistByRepairId(repairId)){
					if(user.deleteTaskByRepairId(repairId)){
						Log.e("完成维修删除任务", repairId + "删除成功");
					}else{
						Log.e("完成维修删除任务", repairId + "删除失败");
					}
					
				}
				finish();
				break;
			case Config.HANDLER_MSG_REPAIR_COMPELETE_FAIL_1:
				Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
						"json连接失败",uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_REPAIR_COMPELETE_FAIL_3:
				Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
						"json解析出错",uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_REPAIR_STOP_SUCCESS:
				Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
						(String) msg.obj,uploadingdialog, loginbar);
				finish();
				break;
			case Config.HANDLER_MSG_REPAIR_STOP_FAIL_1:
				Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
						"json连接失败",uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_REPAIR_STOP_FAIL_2:
				Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
						"json解析出错",uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_LOACALSAVE_SUCCESS:
				Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
						(String) msg.obj,uploadingdialog, loginbar);
				bundle.putString(Config.FUNCTIONCODE, functioncode);
				bundle.putString(Config.PEOPLETYPE, peopleType);
				bundle.putString(Config.TASKSTATE, Config.TASKSTATE_DOING);
				bundle.putString(Config.REPAIRID, task.getRepairId());
				intent = new Intent(ServiceScheduleAccomplishActivity.this,
						ServiceScheduleActivity.class);
				intent.putExtras(bundle);
				startActivity(intent);
				finish();
				break;
			case Config.HANDLER_MSG_FAIL:
				if (uploadingdialog != null) {
					Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
							(String) msg.obj,uploadingdialog, loginbar);
				}
				loginbar.setVisibility(View.INVISIBLE);
				Toast.makeText(ServiceScheduleAccomplishActivity.this,
						(String) msg.obj, Toast.LENGTH_SHORT).show();
			case Config.HANDLER_MSG_FAIL_4:
				if (uploadingdialog != null) {
					Tool.judgedialog(ServiceScheduleAccomplishActivity.this,
							(String) msg.obj,uploadingdialog, loginbar);
				}
				loginbar.setVisibility(View.INVISIBLE);
				Toast.makeText(ServiceScheduleAccomplishActivity.this,
						(String) msg.obj, Toast.LENGTH_SHORT).show();
				finish();
				break;
			case Config.HANDLER_MSG_GETTASK_FAIL:
				if (uploadingdialog != null) {
					if (uploadingdialog.isShowing()) {
						uploadingdialog.dismiss();
					}
				}
				loginbar.setVisibility(View.INVISIBLE);
				new AlertDialog.Builder(ServiceScheduleAccomplishActivity.this)
						.setTitle("提醒")
						.setMessage((String) msg.obj)
						.setPositiveButton(
								"取消",
								new android.content.DialogInterface.OnClickListener() {

									@Override
									public void onClick(DialogInterface arg0,
											int arg1) {
										// TODO Auto-generated method stub
										if(user.isTaskExistByRepairId(repairId)){
											if(user.deleteTaskByRepairId(repairId)){
												Log.e("提醒>>>删除任务", repairId + "删除成功");
											}else{
												Log.e("提醒>>>删除任务", repairId + "删除失败");
											}
											
										}
										finish();
									}
								}).create().show();
				break;
			case Config.HANDLER_MSG_GETREPAIRE_TASK_SUCCESS:
				loginbar.setVisibility(View.INVISIBLE);
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}
	};


	public static final DisplayImageOptions options = new DisplayImageOptions.Builder()
			.cacheInMemory(false) // 设置下载的图片是否缓存在内存中
			.cacheOnDisk(false).bitmapConfig(Bitmap.Config.RGB_565) // 设置下载的图片是否缓存在SD卡中
			.displayer(new RoundedBitmapDisplayer(10)) // 设置成圆角图片
			.build();

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_serviceschedule_accomplish);

		initData();
		initViews();
		initEvents();
	
		if(!user.isTaskExistByRepairId(repairId)){
			loginbar.setVisibility(View.VISIBLE);
			new Thread(getDataRun).start();
		}
		

	}

	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	private void initData(){
		intent = getIntent();
		bundle = intent.getExtras();
		functioncode = bundle.getString(Config.FUNCTIONCODE);
		houseFullName = bundle.getString(Config.HOUSEFULLNAME);
		taskstate = bundle.getString(Config.TASKSTATE);
		peopleType = bundle.getString(Config.PEOPLETYPE);
		repairId = bundle.getString(Config.REPAIRID);
		areaType = bundle.getString(Config.AREATYPE);
		isReporter = bundle.getBoolean(Config.ISREPORTER);
		
		if (functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFOWNER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFNONOWNER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTDISPACHER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSEVER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETOUTDOORPROGRESSLISTOFOWNER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTMANAGER)
				|| functioncode.equals(Config.FUNCTION_REAL_GETPMPROGRESSLIST)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSERVERMANAGER)) {// 进度查看
			realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSDETAIL;
		} else if (functioncode
				.equals(Config.FUNCTION_REAL_GETDISPATCHTASKLIST)) {// 报修分配
			realfunctioncode = Config.FUNCTION_REAL_GETDISPATCHTASKDETAIL;
		} else if (functioncode
				.equals(Config.FUNCTION_REAL_GETREDISPATCHTASKLIST)) {// 改派
			realfunctioncode = Config.FUNCTION_REAL_GETREDISPATCHTASKDETAIL;
		} else if (functioncode.equals(Config.FUNCTION_REAL_GETREVISITTASKLIST)) {// 回访
			realfunctioncode = Config.FUNCTION_REAL_GETREVISITTASKDETAIL;
			//realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSDETAIL;
		} else if (functioncode.equals(Config.FUNCTION_REAL_GETPMREVISITLIST)) {// 项目经理终止回访
			realfunctioncode = Config.FUNCTION_REAL_GETPMREVISITDETAIL;
		}else if (functioncode.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST) 
				|| functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER)) {// 维修任务、我的提单（服务人员）
			realfunctioncode = Config.FUNCTION_REAL_GETREPAIRTASKDETAIL;
		} else if (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && !peopleType.equals(Config.SERVER)) {// 我的提单
			realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSDETAIL;
		}
		
		user = SingleSample.getInstance(this).getUser();
		
		if(user.isTaskExistByRepairId(repairId)){
			task = user.getTasksByRepairId(repairId).get(0);
		}
		
		if (null != user) {
			if (null != user.getSessionId()
					&& !user.getSessionId().equals("")) {
				sessionId = user.getSessionId();
			}
		}
	}
	@SuppressLint("NewApi")
	@Override
	protected void initViews() {
		// TODO Auto-generated method stub
		titleCenterTv = (TextView) findViewById(R.id.titlebar_both_center_title);
		leftLinLayout = (LinearLayout) findViewById(R.id.titlebar_both_left_layout);

		guideTimeLineLl = (LinearLayout) findViewById(R.id.ll_guide_time_line);
		submitBtn = (Button) findViewById(R.id.goto_assess);
		loginbar = (ProgressBar) findViewById(R.id.serviceschedule_accomplish_progressBar);
		uploadingdialog = new CustomLoadingDialog(
				ServiceScheduleAccomplishActivity.this, "正在上传...");
		accomplish_tasknum = (TextView) findViewById(R.id.sch_accomplish_tasknum);
		accomplish_address = (TextView) findViewById(R.id.sch_accomplish_address);
		accomplish_object = (TextView) findViewById(R.id.sch_accomplish_serviceobject);
		accomplish_repairtime = (TextView) findViewById(R.id.sch_accomplish_repairtime);
		accomplish_username = (TextView) findViewById(R.id.sch_accomplish_usermassage_name);
		accomplish_telephone = (TextView) findViewById(R.id.sch_accomplish_usermassage_telephone);
		accomplish_repairdescribe = (TextView) findViewById(R.id.sch_accomplish_repairdescribe);
		report_location = (TextView) findViewById(R.id.report_location);

		accomplish_servicetime = (TextView) findViewById(R.id.sch_accomplish_servicetime);
		accomplish_serviceman = (TextView) findViewById(R.id.sch_accomplish_serviceman_name);
		accomplish_servicetelephone = (TextView) findViewById(R.id.sch_accomplish_serviceman_telephone);
		accomplish_servicedescribe = (EditText) findViewById(R.id.sch_accomplish_servicedescribe);
		reportVoiceTime = (TextView) findViewById(R.id.accomplish_report_recordtime);
		serviceVoiceTime = (TextView) findViewById(R.id.accomplish_solve_recordtime);
		repoertvoice = (ImageView) findViewById(R.id.accomplish_report_voiceView);
		repairimage1 = (ImageView) findViewById(R.id.accomplish_report_imageView1);
		repairimage2 = (ImageView) findViewById(R.id.accomplish_report_imageView2);
		servicevoice = (ImageView) findViewById(R.id.accomplish_solve_voiceView);
		serviceimage1 = (ImageView) findViewById(R.id.accomplish_solve_imageView1);
		serviceimage2 = (ImageView) findViewById(R.id.accomplish_solve_imageView2);
		submitBtn = (Button) findViewById(R.id.goto_assess);
		saveBtn = (TextView) findViewById(R.id.titlebar_both_right_text);
		pushBtn = (Button) findViewById(R.id.sch_accomplish_push_service);
		stopBtn = (Button) findViewById(R.id.sch_accomplish_stop_service);

		badgeImage1 = new BadgeView(this, serviceimage1);
		badgeImage2 = new BadgeView(this, serviceimage2);
		badgeVoice = new BadgeView(this, servicevoice);
		if (functioncode.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST)
				|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER)&& isReporter)
				&& (taskstate.equals(Config.TASKSTATE_TODO) 
						|| taskstate.equals(Config.TASKSTATE_DOING) 
						|| taskstate.equals(Config.TASKSTATE_TOPOST)
						|| taskstate.equals(Config.TASKSTATE_BEASKED))) {// 维修任务
				if (null != task && task.getRepairNum() != null) {
					accomplish_tasknum.setText(task.getRepairNum());
				}
				/*if (null != task && task.getHouseAllName() != null) {
					accomplish_address.setText(task.getHouseAllName());
				}*/
				if (null != houseFullName && !houseFullName.equals("")) {
					accomplish_address.setText(houseFullName);
				}
				// 维修区域信息拼接
				if (null != task && task.getAreaType_typeCode() != null) {
					if (task.getAreaType_typeCode().equals(Config.AREACODE_OUTDOOR)) {
						areaname = Config.AREANAME_PUBLIC;
					} else {
						areaname = Config.AREANAME_INDOOR;
					}
				} else if (null != task && task.getHouse_houseType_typeCode() != null) {
					if (task.getHouse_houseType_typeCode().equals(
							Config.AREACODE_OUTDOOR)) {
						areaname = Config.AREANAME_PUBLIC;
					} else {
						areaname = Config.AREANAME_INDOOR;
					}
				}
				if (null != task && task.getRepairObject() != null) {
					accomplish_object.setText(areaname + "/" + task.getRepairObject());
				}
				
				if (null != task && null != task.getReportTime()
						&& !task.getReportTime().equals("")) {
					if (task.getReportTime().length() > Config.TIMELENGTH) {
						accomplish_repairtime.setText(task.getReportTime()
								.substring(0, Config.TIMELENGTH));
					} else {
						accomplish_repairtime.setText(task.getReportTime());
					}
				}
				if (null != task && null != task.getRepairTime()
						&& !task.getRepairTime().equals("")) {
					Log.e("task.getRepairTime().length()--->33", task
							.getRepairTime().length() + "");

					if (null != task && task.getRepairTime().length() > Config.TIMELENGTH) {
						Log.e("task.getRepairTime().length()--->44", task
								.getRepairTime().length() + "");
						/*accomplish_servicetime.setText(task.getRepairTime()
								.substring(0, Config.TIMELENGTH));*/
						accomplish_servicetime.setText(task.getFinishTime()
								.substring(0, Config.TIMELENGTH));
					} else {
						//accomplish_servicetime.setText(task.getRepairTime());
						accomplish_servicetime.setText(task.getFinishTime());
					}
				}
				if(null != task){
					accomplish_username.setText(task.getReporter_realName());
					accomplish_repairdescribe.setText(task.getProblemDescript());
					accomplish_serviceman.setText(task.getServer_realName());
					accomplish_telephone.setText(task.getReporter_phone());
					accomplish_servicetelephone.setText(task.getServer_mobilePhone());
					accomplish_servicedescribe.setText(task.getSolvedDescript());
				}
				
				if (null != task && null != task.getProblemImage1()
						&& !task.getProblemImage1().equals("")) {
					reportimagePath1 = task.getProblemImage1();
					repairimage1.setVisibility(View.VISIBLE);
					ImageLoader.getInstance()
							.displayImage(
									"file://" + Config.IMAGE_PATH
											+ task.getProblemImage1(),
									repairimage1, options);
				} else {
					repairimage1.setVisibility(View.INVISIBLE);
				}
				if (null != task && null != task.getProblemImage2()
						&& !task.getProblemImage2().equals("")) {
					reportimagePath2 = task.getProblemImage2();
					repairimage2.setVisibility(View.VISIBLE);
					ImageLoader.getInstance()
							.displayImage(
									"file://" + Config.IMAGE_PATH
											+ task.getProblemImage2(),
									repairimage2, options);
				} else {
					repairimage2.setVisibility(View.INVISIBLE);
				}
				if (null != task && null != task.getProblemVoice()
						&& !task.getProblemVoice().equals("")) {
					int voicetime = Tool.voiceTime(ServiceScheduleAccomplishActivity.this,Config.VOICE_PATH+task.getProblemVoice());
					int realvoicetime = (int) voicetime/1000;
					reportvoicePath = task.getProblemVoice();
					repoertvoice.setVisibility(View.VISIBLE);
					reportVoiceTime.setVisibility(View.VISIBLE);
					reportVoiceTime.setText(realvoicetime+"'");
					//assign_repair_voice.setVisibility(View.VISIBLE);
					Log.e("realvoicetime", realvoicetime+"'");
					
				} else {
					repoertvoice.setVisibility(View.INVISIBLE);
					reportVoiceTime.setVisibility(View.INVISIBLE);
				}
			
		}

		if (functioncode.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST)
				|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER)&& isReporter)
				&& (taskstate.equals(Config.TASKSTATE_TODO) 
						|| taskstate.equals(Config.TASKSTATE_DOING) 
						|| taskstate.equals(Config.TASKSTATE_TOPOST)
						|| taskstate.equals(Config.TASKSTATE_BEASKED))) {// 维修任务
				accomplish_servicedescribe.setEnabled(true);
				if(null != task){
					if (null == task.getSolvedDescript()
							|| task.getSolvedDescript().equals("")) {
						accomplish_servicedescribe.setHint("请输入维修描述");
						accomplish_servicedescribe.setText(task.getSolvedDescript());
					} else {
						accomplish_servicedescribe.setText(task.getSolvedDescript());
					}
				}
		}

		if (functioncode.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST)
				|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER)&& isReporter)
				&& (taskstate.equals(Config.TASKSTATE_TODO) 
						|| taskstate.equals(Config.TASKSTATE_DOING) 
						|| taskstate.equals(Config.TASKSTATE_TOPOST)
						|| taskstate.equals(Config.TASKSTATE_BEASKED))) {// 维修任务
				if (null != task && null != task.getSolvedImage1()
						&& !task.getSolvedImage1().equals("")) {
					solveimagePath1 = task.getSolvedImage1();
				}
				if (null != task && null != task.getSolvedImage2()
						&& !task.getSolvedImage2().equals("")) {
					solveimagePath2 = task.getSolvedImage2();
				}
				if (null != task && null != task.getSolvedVoice()
						&& !task.getSolvedVoice().equals("")) {
					solvevoicePath = task.getSolvedVoice();
					voiceTime = Integer.parseInt(task.getSolvedVoiceTime());
				}
				if (!solveimagePath1.equals("")) {
					serviceimage2.setVisibility(View.VISIBLE);
					badgeImage1.setText("  ");
					badgeImage1.setTextSize(12);
					badgeImage1.setBackgroundResource(R.drawable.badge_view);
					badgeImage1.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
					badgeImage1.setBadgeMargin(0, 0);
					badgeImage1.toggle();
					badgeImage1.show();
					badgeImage1.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							imageRealPath1 = imageRealPath2;
							solveimagePath1 = solveimagePath2;
							solveimagePath2 = "";
							imageRealPath2 = "";

							if (solveimagePath1.equals("")) {
								badgeImage1.hide();
								ImageLoader.getInstance().displayImage(null,
										serviceimage1, options);

								serviceimage2.setVisibility(View.INVISIBLE);
							} else {
								badgeImage1.show();
								ImageLoader.getInstance().displayImage(
										"file://" + Config.IMAGE_PATH
												+ solveimagePath1, serviceimage1,
										options);
								ImageLoader.getInstance().displayImage(null,
										serviceimage1, options);
							}
						}
					});
					ImageLoader.getInstance().displayImage(
							"file://" + Config.IMAGE_PATH + solveimagePath1,
							serviceimage1, options);
				}
				if (!solveimagePath2.equals("")) {
					serviceimage2.setVisibility(View.VISIBLE);
					badgeImage2.setText("  ");
					badgeImage2.setTextSize(12);
					badgeImage2.setBackgroundResource(R.drawable.badge_view);
					badgeImage2.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
					badgeImage2.setBadgeMargin(0, 0);
					badgeImage2.toggle();
					badgeImage2.show();
					badgeImage2.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							solveimagePath2 = "";
							imageRealPath2 = "";
							badgeImage2.hide();
							ImageLoader.getInstance().displayImage(null,
									serviceimage2, options);

						}
					});
					ImageLoader.getInstance().displayImage(
							"file://" + Config.IMAGE_PATH + solveimagePath2,
							serviceimage2, options);
				}

				if (!solvevoicePath.equals("")) {

					servicevoice.setBackground(getResources().getDrawable(
							R.drawable.record_voice));
					badgeVoice.setText("  ");
					badgeVoice.setTextSize(12);
					badgeVoice.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
					badgeVoice.setBackgroundResource(R.drawable.badge_view);
					badgeVoice.setBadgeMargin(0, 0);
					badgeVoice.toggle();
					badgeVoice.show();
					badgeVoice.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub

							badgeVoice.hide();
							solvevoicePath = "";
							serviceVoiceTime.setVisibility(View.INVISIBLE);
							servicevoice.setBackground(getResources().getDrawable(
									R.drawable.btn_voice_taken));
						}
					});

					serviceVoiceTime.setVisibility(View.VISIBLE);
					serviceVoiceTime.setText(voiceTime + "'");
				} else {
					serviceVoiceTime.setVisibility(View.INVISIBLE);
				}
			}
	}

	@SuppressLint("NewApi")
	@Override
	protected void initEvents() {

		// TODO Auto-generated method stub
		// 电话
		accomplish_telephone.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		accomplish_telephone.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		accomplish_servicetelephone.getPaint().setFlags(
				Paint.UNDERLINE_TEXT_FLAG);
		accomplish_servicetelephone.getPaint().setFlags(
				Paint.UNDERLINE_TEXT_FLAG);

		saveBtn.setOnClickListener(this);
		pushBtn.setOnClickListener(this);
		stopBtn.setOnClickListener(this);

		submitBtn.setOnClickListener(this);
		repairimage1.setOnClickListener(this);
		repairimage2.setOnClickListener(this);
		serviceimage1.setOnClickListener(this);
		serviceimage2.setOnClickListener(this);

		repoertvoice.setOnClickListener(this);
		servicevoice.setOnClickListener(this);
		
		leftLinLayout.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {				
				saveData();
				finish();
			}
		});

		accomplish_telephone.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				// TODO Auto-generated method stub
				intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"
						+ accomplish_telephone.getText().toString()));
				startActivity(intent);
			}
		});

		accomplish_servicetelephone.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				// TODO Auto-generated method stub
				intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"
						+ accomplish_servicetelephone.getText().toString()));
				startActivity(intent);
			}
		});

		
		// 派单员的维修进度
		if (functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTDISPACHER)// 维修进度
				|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.DISPATCHER))//我的提单（派单员）
				) {
			if (taskstate.equals(Config.TASKSTATE_REVISIT)) {// 待回访
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setText("回访");
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_EVALUATE)) {// 待评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_REPORTER_EVALUATE)
					|| taskstate.equals(Config.TASKSTATE_HOST_EVALUATE)) {// 待提单人评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}else {// 完成

				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}

		}
		// 部门派单员的维修进度
		else if (functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTMANAGER)// 维修进度
				|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.DEPART_DISPATCHER) && isReporter)//我的提单（部门派单员）
				) {
			if (taskstate.equals(Config.TASKSTATE_REVISIT)) {// 待回访
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_EVALUATE)) {// 待评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_REPORTER_EVALUATE)
					|| taskstate.equals(Config.TASKSTATE_HOST_EVALUATE)) {// 待提单人评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}else {// 完成

				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}

		}// 部门经理的维修进度
		else if (functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSERVERMANAGER)// 维修进度
				|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER_MANAGER))//我的提单（部门经理）
				) {
			if (taskstate.equals(Config.TASKSTATE_REVISIT)) {// 待回访
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_EVALUATE)) {// 待评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_REPORTER_EVALUATE)
					|| taskstate.equals(Config.TASKSTATE_HOST_EVALUATE)) {// 待提单人评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}else {// 完成

				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}

		}
		// 维修人员的维修进度
		else if (functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSEVER)
				|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER) &&isReporter 
				&&(taskstate.equals(Config.TASKSTATE_REVISIT) || taskstate.equals(Config.TASKSTATE_EVALUATE)||taskstate.equals(Config.TASKSTATE_REPORTER_EVALUATE)// 待业主评价
						|| taskstate.equals(Config.TASKSTATE_HOST_EVALUATE) ))
				) {// 维修进度
			if (taskstate.equals(Config.TASKSTATE_REVISIT)) {// 待回访
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_EVALUATE)) {// 待评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_REPORTER_EVALUATE)// 待业主评价
					|| taskstate.equals(Config.TASKSTATE_HOST_EVALUATE)) {// 待提单人评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}else {// 完成

				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}

		} else if (functioncode.equals(Config.FUNCTION_REAL_GETREVISITTASKLIST)) {// 回访
			saveBtn.setVisibility(View.GONE);
			pushBtn.setVisibility(View.GONE);
			stopBtn.setVisibility(View.GONE);
			guideTimeLineLl.setVisibility(View.GONE);
			submitBtn.setText("回访");
			accomplish_servicedescribe.setBackground(null);
			titleCenterTv.setText("维修详情");

		} else if (functioncode.equals(Config.FUNCTION_REAL_GETPMPROGRESSLIST)
				||(functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.DEPART_MANAGER))//我的提单（项目经理）
				) {// 项目经理进度列表

			if (taskstate.equals(Config.TASKSTATE_REVISIT)) {// 待回访
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				guideTimeLineLl.setVisibility(View.GONE);
				submitBtn.setText("终止回访");
				accomplish_servicedescribe.setBackground(null);
				titleCenterTv.setText("维修详情");

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_EVALUATE)) {// 待评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else if (taskstate.equals(Config.TASKSTATE_REPORTER_EVALUATE)// 待业主评价
					|| taskstate.equals(Config.TASKSTATE_HOST_EVALUATE)) {// 待提单人评价
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}else {// 完成

				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}
		} else if (functioncode.equals(Config.FUNCTION_REAL_GETPMREVISITLIST)) {// 项目经理终止回访
			saveBtn.setVisibility(View.GONE);
			pushBtn.setVisibility(View.GONE);
			stopBtn.setVisibility(View.GONE);
			guideTimeLineLl.setVisibility(View.GONE);
			submitBtn.setText("终止回访");
			accomplish_servicedescribe.setBackground(null);
			titleCenterTv.setText("维修详情");

		} else if (functioncode.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST)// 维修任务
				|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER)&& isReporter)
				) {
			guideTimeLineLl.setVisibility(View.GONE);
			submitBtn.setVisibility(View.GONE);
			titleCenterTv.setText("维修详情");
			if (taskstate.equals(Config.TASKSTATE_TODO)) {// 待处理

				serviceimage1.setBackground(getResources().getDrawable(
						R.drawable.defect_compose_pic_add_highlighted));
				serviceimage2.setVisibility(View.GONE);
				serviceVoiceTime.setVisibility(View.GONE);
				accomplish_servicedescribe.setEnabled(true);
				accomplish_servicedescribe.setText("");
				accomplish_servicedescribe.setEms(3);
			} else if (taskstate.equals(Config.TASKSTATE_BEASKED)
					|| taskstate.equals(Config.TASKSTATE_DOING)
					|| taskstate.equals(Config.TASKSTATE_TOPOST)) {// 维修中、待上报

				accomplish_servicedescribe.setEnabled(true);
				accomplish_servicedescribe.setEms(3);

			}else {// 完成

				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}

		} // 户主和非户主的维修进度
		else if (functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFOWNER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFNONOWNER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETOUTDOORPROGRESSLISTOFOWNER)
				|| (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY)&& !isReporter)		
				) {// 维修进度
			if (taskstate.equals(Config.TASKSTATE_REVISIT)) {// 待回访
				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				submitBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			} else {// 完成

				saveBtn.setVisibility(View.GONE);
				pushBtn.setVisibility(View.GONE);
				stopBtn.setVisibility(View.GONE);
				accomplish_servicedescribe.setBackground(null);

				titleCenterTv.setText("完成维修");
			}

		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.goto_assess:
			if (submitBtn.getText().equals("去评价")) {

				bundle.putString(Config.FUNCTIONCODE, functioncode);
				bundle.putString(Config.TASKSTATE, Config.TYPECODE_EVALUATE);
				bundle.putString(Config.REPAIRID, repairId);
				bundle.putString("areaType", areaType);
				Intent intent = new Intent(
						ServiceScheduleAccomplishActivity.this,
						ServiceScheduleUserValueActivity.class);
				intent.putExtras(bundle);
				startActivity(intent);
				finish();
			} else if (submitBtn.getText().equals("回访")) {
				bundle.putString(Config.FUNCTIONCODE,
						Config.FUNCTION_RETURNVISIT);
				bundle.putString(Config.TASKSTATE, Config.TYPECODE_REVISIT);
				bundle.putString(Config.REPAIRID, repairId);
				bundle.putString(Config.REALNAME, task.getReporter_realName());
				bundle.putString(Config.PHONENUM, task.getReporter_phone());
				Intent intent = new Intent(
						ServiceScheduleAccomplishActivity.this,
						VisitDetailActivity.class);
				intent.putExtras(bundle);
				startActivity(intent);
				finish();
			} else if (submitBtn.getText().equals("终止回访")) {
				bundle.putString(Config.FUNCTIONCODE,
						Config.FUNCTION_PMREVISIT);
				bundle.putString(Config.TASKSTATE, Config.TYPECODE_REVISIT);
				bundle.putString(Config.REPAIRID, repairId);
				bundle.putString(Config.REALNAME, task.getReporter_realName());
				bundle.putString(Config.PHONENUM, task.getReporter_phone());
				Intent intent = new Intent(
						ServiceScheduleAccomplishActivity.this,
						VisitDetailActivity.class);
				intent.putExtras(bundle);
				startActivity(intent);
				finish();
			}

			break;
		case R.id.titlebar_both_right_text:
			uploadingdialog = new CustomLoadingDialog(
					ServiceScheduleAccomplishActivity.this, "正在保存...");
			if (uploadingdialog.isShowing()) {
				uploadingdialog.dismiss();
			} else {
				uploadingdialog.show();
			}
			new Thread(saveDataRun).start();
			
			break;
		case R.id.sch_accomplish_push_service:
			saveData();
			
			if (solveimagePath1.equals("")
					&& solveimagePath2.equals("")
					&& solvevoicePath.equals("")
					&& accomplish_servicedescribe.getText().toString()
							.equals("")) {
				Toast.makeText(ServiceScheduleAccomplishActivity.this,
						"维修记录不能为空", Toast.LENGTH_SHORT).show();
			} else {
				// 标准的对话框封装
				final CustomDialog dialog2 = new CustomDialog(
						ServiceScheduleAccomplishActivity.this);
				dialog2.setTitle("上传");
				dialog2.setDetial("是否确认上传？");
				dialog2.setLeftOnClick(new OnClickListener() {
					@Override
					public void onClick(View v) {
						dialog2.dismiss();
					}
				});
				dialog2.show();
				dialog2.setRightOnClick(new OnClickListener() {
					@Override
					public void onClick(View v) {
						dialog2.dismiss();
						uploadingdialog = new CustomLoadingDialog(
								ServiceScheduleAccomplishActivity.this,
								"完成维修...");
						if (uploadingdialog.isShowing()) {
							uploadingdialog.dismiss();
						} else {
							uploadingdialog.show();
						}
						new Thread(repairCompeleteRun).start();
						
					}
				});
				dialog2.show();
			}

			break;
		case R.id.sch_accomplish_stop_service:
			// 标准的对话框封装
			final CustomDialog dialog3 = new CustomDialog(
					ServiceScheduleAccomplishActivity.this);
			dialog3.setTitle("停止");
			dialog3.setDetial("是否确认停止维修？");
			dialog3.setLeftOnClick(new OnClickListener() {
				@Override
				public void onClick(View v) {
					dialog3.dismiss();
				}
			});
			dialog3.show();
			dialog3.setRightOnClick(new OnClickListener() {
				@Override
				public void onClick(View v) {
					dialog3.dismiss();
					uploadingdialog = new CustomLoadingDialog(
							ServiceScheduleAccomplishActivity.this,
							"停止维修...");
					if (uploadingdialog.isShowing()) {
						uploadingdialog.dismiss();
					} else {
						uploadingdialog.show();
					}
					new Thread(postStopRepairRun).start();

				}
			});
			dialog3.show();
			break;
		case R.id.accomplish_report_imageView1:

			Intent intent5 = new Intent(
					ServiceScheduleAccomplishActivity.this,
					ViewPagerActivity.class);
			intent5.putExtra("image1", "file://" + Config.IMAGE_PATH
					+ reportimagePath1);
			if (!reportimagePath2.equals("")) {
				intent5.putExtra("image2", "file://" + Config.IMAGE_PATH
						+ reportimagePath2);
			}
			startActivity(intent5);

			break;
		case R.id.accomplish_report_imageView2:

			Intent intent1 = new Intent(
					ServiceScheduleAccomplishActivity.this,
					ViewPagerActivity.class);
			intent1.putExtra("image1", "file://" + Config.IMAGE_PATH
					+ reportimagePath2);
			intent1.putExtra("image2", "file://" + Config.IMAGE_PATH
					+ reportimagePath1);

			startActivity(intent1);

			break;
		case R.id.accomplish_report_voiceView:
			File clickfile = new File(Config.VOICE_PATH + reportvoicePath);
			Intent it = new Intent();
			it.setAction(Intent.ACTION_VIEW);

			it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			it.putExtra("oneshot", 0);
			it.putExtra("configchange", 0);
			it.setDataAndType(Uri.parse("file:" + clickfile.getPath()),
					"audio/*");
			startActivity(it);
			break;
		case R.id.accomplish_solve_imageView1:
			if(peopleType.equals(Config.SERVER)){
				if (solveimagePath1.equals("")) {

					final Dialog dlg = new Dialog(
							ServiceScheduleAccomplishActivity.this,
							R.style.ActionSheet);
					LayoutInflater inflater = (LayoutInflater) this
							.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
					LinearLayout layout = (LinearLayout) inflater.inflate(
							R.layout.activity_writepaper_dialog, null);
					final int cFullFillWidth = 10000;
					layout.setMinimumWidth(cFullFillWidth);

					TextView mContent1 = (TextView) layout
							.findViewById(R.id.tv_content1);
					TextView mContent2 = (TextView) layout
							.findViewById(R.id.tv_content2);
					TextView mCancel = (TextView) layout
							.findViewById(R.id.tv_cancel);
					// 拍摄选择照片
					mContent1.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							String temName = DateFormat.format("yyMMdd_hhmmss",
									System.currentTimeMillis())
									+ "_"
									+ (Math.random() * 100) + ".jpg";
							imageRealPath1 = Config.IMAGE_PATH + File.separator
									+ temName;
							File file = new File(imageRealPath1);
							if (file.exists()) {
								file.delete();
							}
							imageUri = Uri.fromFile(file);
							Intent intent = new Intent(
									MediaStore.ACTION_IMAGE_CAPTURE);

							intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
							startActivityForResult(intent, 1);

							dlg.dismiss();
						}
					});
					// 从相册中选择照片
					mContent2.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							Intent choosePictureIntent = new Intent(
									Intent.ACTION_PICK,
									android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
							choosePictureIntent.setType("image/jpeg");
							startActivityForResult(choosePictureIntent, 2);
							dlg.dismiss();
						}
					});

					mCancel.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub

							dlg.dismiss();

						}
					});

					Window w = dlg.getWindow();
					WindowManager.LayoutParams lp = w.getAttributes();
					lp.x = 0;
					final int cMakeBottom = -1000;
					lp.y = cMakeBottom;
					lp.gravity = Gravity.BOTTOM;
					dlg.onWindowAttributesChanged(lp);
					dlg.setCanceledOnTouchOutside(false);
					dlg.setContentView(layout);
					dlg.show();
				}
				// 已经有图片了就直接放大显示
				else {

					Intent intent0 = new Intent(
							ServiceScheduleAccomplishActivity.this,
							ViewPagerActivity.class);
					intent0.putExtra("image1", "file://" + Config.IMAGE_PATH
							+ solveimagePath1);
					if (!solveimagePath2.equals("")) {
						intent0.putExtra("image2", "file://"
								+ Config.IMAGE_PATH + solveimagePath2);
					}
					startActivity(intent0);
				}

				break;
			}else{
				Intent n = new Intent(ServiceScheduleAccomplishActivity.this,
						ViewPagerActivity.class);
				n.putExtra("image1", "file://" + Config.IMAGE_PATH
						+ solveimagePath1);
				if (!solveimagePath2.equals("")) {
					n.putExtra("image2", "file://" + Config.IMAGE_PATH
							+ solveimagePath2);
				}
				startActivity(n);
			}
			
			break;
		case R.id.accomplish_solve_imageView2:
			if(peopleType.equals(Config.SERVER)){
				if (solveimagePath2.equals("")) {

					final Dialog dlg = new Dialog(this, R.style.ActionSheet);
					LayoutInflater inflater = (LayoutInflater) this
							.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
					LinearLayout layout = (LinearLayout) inflater.inflate(
							R.layout.activity_writepaper_dialog, null);
					final int cFullFillWidth = 10000;
					layout.setMinimumWidth(cFullFillWidth);

					TextView mContent1 = (TextView) layout
							.findViewById(R.id.tv_content1);
					TextView mContent2 = (TextView) layout
							.findViewById(R.id.tv_content2);
					TextView mCancel = (TextView) layout
							.findViewById(R.id.tv_cancel);
					// 拍摄选择照片
					mContent1.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							String temName = DateFormat.format("yyMMdd_hhmmss",
									System.currentTimeMillis())
									+ "_"
									+ (Math.random() * 100) + ".jpg";
							imageRealPath2 = Config.IMAGE_PATH + File.separator
									+ temName;
							File file = new File(imageRealPath2);
							if (file.exists()) {
								file.delete();
							}
							imageUri = Uri.fromFile(file);
							Intent intent = new Intent(
									MediaStore.ACTION_IMAGE_CAPTURE);

							intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
							startActivityForResult(intent, 3);

							dlg.dismiss();
						}
					});
					// 从相册中选择照片
					mContent2.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							Intent choosePictureIntent = new Intent(
									Intent.ACTION_PICK,
									android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
							choosePictureIntent.setType("image/jpeg");
							startActivityForResult(choosePictureIntent, 4);
							dlg.dismiss();
						}
					});

					mCancel.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							dlg.dismiss();
						}
					});

					Window w = dlg.getWindow();
					WindowManager.LayoutParams lp = w.getAttributes();
					lp.x = 0;
					final int cMakeBottom = -1000;
					lp.y = cMakeBottom;
					lp.gravity = Gravity.BOTTOM;
					dlg.onWindowAttributesChanged(lp);
					dlg.setCanceledOnTouchOutside(false);
					dlg.setContentView(layout);
					dlg.show();
				} else {
					Intent intent2 = new Intent(this, ViewPagerActivity.class);
					intent2.putExtra("image1", "file://" + Config.IMAGE_PATH
							+ solveimagePath2);
					intent2.putExtra("image2", "file://" + Config.IMAGE_PATH
							+ solveimagePath1);
					startActivity(intent2);
				}
			}else{
				Intent intent3 = new Intent(
						ServiceScheduleAccomplishActivity.this,
						ViewPagerActivity.class);
				intent3.putExtra("image1", "file://" + Config.IMAGE_PATH
						+ solveimagePath2);
				intent3.putExtra("image2", "file://" + Config.IMAGE_PATH
						+ solveimagePath1);
				startActivity(intent3);
			}
			
			break;
		case R.id.accomplish_solve_voiceView:
			if(peopleType.equals(Config.SERVER)){
				if (solvevoicePath.equals("")) {
					File parent2 = new File("/sdcard/NewWorld_APP2_Voice/");
					if (!parent2.exists()) {
						parent2.mkdirs();
					}
					Intent intent4 = new Intent(
							ServiceScheduleAccomplishActivity.this,
							SoundActivity.class);
					startActivityForResult(intent4, 7);
				} else {
					File clickfile0 = new File(Config.VOICE_PATH
							+ solvevoicePath);
					Intent a = new Intent();
					a.setAction(Intent.ACTION_VIEW);

					a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					a.putExtra("oneshot", 0);
					a.putExtra("configchange", 0);

					a.setDataAndType(Uri.parse("file:" + clickfile0.getPath()),
							"audio/*");
					startActivity(a);
				}
			}else{
				File clickfile1 = new File(Config.VOICE_PATH + solvevoicePath);
				Intent it1 = new Intent();
				it1.setAction(Intent.ACTION_VIEW);
				it1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				it1.putExtra("oneshot", 0);
				it1.putExtra("configchange", 0);
				it1.setDataAndType(Uri.parse("file:" + clickfile1.getPath()),
						"audio/*");
				startActivity(it1);
			}
			break;
		default:
			break;

		}
	}

	@SuppressLint("NewApi")
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == Activity.RESULT_OK && requestCode == 1) {
			Bundle b = new Bundle();
			b.putString("imagePath", imageRealPath1);
			Intent intent = new Intent(ServiceScheduleAccomplishActivity.this,
					ChoosephotoActivity.class);
			flag = 1;
			intent.putExtras(b);
			startActivityForResult(intent, 5);
		} else if (resultCode == Activity.RESULT_OK && requestCode == 2) {
			Bundle bundle = new Bundle();
			Uri uri = data.getData();

			String[] filePathColumn = { MediaStore.Images.Media.DATA };
			Log.e("picture", uri.toString());
			Cursor cursor = getContentResolver().query(uri, filePathColumn,
					null, null, null);
			cursor.moveToFirst();

			int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
			imageRealPath1 = cursor.getString(columnIndex);
			cursor.close();
			bundle.putString("imagePath", imageRealPath1);
			Intent intent = new Intent(ServiceScheduleAccomplishActivity.this,
					ChoosephotoActivity.class);
			flag = 2;
			intent.putExtras(bundle);
			startActivityForResult(intent, 5);
		}

		else if (resultCode == Activity.RESULT_OK && requestCode == 3) {
			Bundle b1 = new Bundle();
			b1.putString("imagePath", imageRealPath2);
			Intent intent1 = new Intent(ServiceScheduleAccomplishActivity.this,
					ChoosephotoActivity.class);
			flag = 1;
			intent1.putExtras(b1);
			startActivityForResult(intent1, 6);
		} else if (resultCode == Activity.RESULT_OK && requestCode == 4) {
			Bundle bundle = new Bundle();
			Uri uri = data.getData();
			String[] filePathColumn = { MediaStore.Images.Media.DATA };
			Log.e("picture", uri.toString());
			Cursor cursor = getContentResolver().query(uri, filePathColumn,
					null, null, null);
			cursor.moveToFirst();

			int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
			imageRealPath2 = cursor.getString(columnIndex);
			cursor.close();
			bundle.putString("imagePath", imageRealPath2);
			Intent intent = new Intent(ServiceScheduleAccomplishActivity.this,
					ChoosephotoActivity.class);
			flag = 2;
			intent.putExtras(bundle);
			startActivityForResult(intent, 6);
		} else if (resultCode == Activity.RESULT_OK && requestCode == 5) {
			solveimagePath1 = data.getStringExtra("imagePath");
			imageRealPath1 = Config.IMAGE_PATH + solveimagePath1;
		} else if (resultCode == Activity.RESULT_OK && requestCode == 6) {
			solveimagePath2 = data.getStringExtra("imagePath");
			imageRealPath2 = Config.IMAGE_PATH + solveimagePath2;
		} else if (resultCode == Activity.RESULT_OK && requestCode == 7) {
			solvevoicePath = data.getStringExtra("voiceName");
			voiceTime = data.getIntExtra("voiceTime", 0);
		}
		if (!solveimagePath1.equals("")) {

			badgeImage1.setText("  ");
			badgeImage1.setTextSize(12);
			badgeImage1.setBackgroundResource(R.drawable.badge_view);
			badgeImage1.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
			badgeImage1.setBadgeMargin(0, 0);
			badgeImage1.toggle();
			badgeImage1.show();
			badgeImage1.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					imageRealPath1 = imageRealPath2;
					solveimagePath1 = solveimagePath2;
					solveimagePath2 = "";
					imageRealPath2 = "";

					if (solveimagePath1.equals("")) {
						badgeImage1.hide();
						ImageLoader.getInstance().displayImage(null,
								serviceimage1, options);

						serviceimage2.setVisibility(View.INVISIBLE);
					} else {
						badgeImage2.hide();
						ImageLoader.getInstance()
								.displayImage(
										"file://" + Config.IMAGE_PATH
												+ solveimagePath1,
										serviceimage1, options);
						ImageLoader.getInstance().displayImage(null,
								serviceimage2, options);

					}
				}
			});
			ImageLoader.getInstance().displayImage(
					"file://" + Config.IMAGE_PATH + solveimagePath1,
					serviceimage1, options);
			getResources().getDrawable(
					R.drawable.defect_compose_pic_add_highlighted);
			serviceimage2.setVisibility(View.VISIBLE);
		}
		if (!solveimagePath2.equals("")) {
			badgeImage2.setText("  ");
			badgeImage2.setTextSize(12);
			badgeImage2.setBackgroundResource(R.drawable.badge_view);
			badgeImage2.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
			badgeImage2.setBadgeMargin(0, 0);
			badgeImage2.toggle();
			badgeImage2.show();
			badgeImage2.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					solveimagePath2 = "";
					imageRealPath2 = "";
					badgeImage2.hide();
					ImageLoader.getInstance().displayImage(null, serviceimage2,
							options);

				}
			});
			ImageLoader.getInstance().displayImage(
					"file://" + Config.IMAGE_PATH + solveimagePath2,
					serviceimage2, options);
		}

		if (!solvevoicePath.equals("")) {
			servicevoice.setBackground(getResources().getDrawable(
					R.drawable.record_voice));
			badgeVoice.setText("  ");
			badgeVoice.setTextSize(12);
			badgeVoice.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
			badgeVoice.setBackgroundResource(R.drawable.badge_view);
			badgeVoice.setBadgeMargin(0, 0);
			badgeVoice.toggle();
			badgeVoice.show();
			badgeVoice.setOnClickListener(new OnClickListener() {
				@SuppressLint("NewApi")
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub

					badgeVoice.hide();
					solvevoicePath = "";
					serviceVoiceTime.setVisibility(View.INVISIBLE);
					servicevoice.setBackground(getResources().getDrawable(
							R.drawable.btn_voice_taken));

				}
			});

			serviceVoiceTime.setVisibility(View.VISIBLE);
			serviceVoiceTime.setText(voiceTime + "'");
		}
	}

	// 上传文件
	// From: CheckTaskDetailActivity
	private Runnable repairCompeleteRun = new Runnable() {

		@Override
		public void run() {
			String url = Config.SERVER_URL
					+ user.getFunctionlistFromUser(
							Config.FUNCTION_REAL_REAPAIRTASKUPLOADFILE).get(0)
							.getFunctionUrl();
			String result = "";
			String flagstr = "";
			int count = 0;
			Map<String, String> params = new HashMap<String, String>();
			ArrayList<File> files = new ArrayList<File>();
			String imagepath1 = Config.IMAGE_PATH + task.getSolvedImage1();
			String imagepath2 = Config.IMAGE_PATH + task.getSolvedImage2();
			String voicepath1 = Config.VOICE_PATH + task.getSolvedVoice();
			File file1, file2, file3;
			
			if (!task.getSolvedImage1().equals("")) {
				file1 = new File(imagepath1);
				if (file1.exists()) {
					files.add(file1);
				}
			}
			if (!task.getSolvedImage2().equals("")) {
				file2 = new File(imagepath2);
				if (file2.exists()) {
					files.add(file2);
				}
			}
			if (!task.getSolvedVoice().equals("")) {
				file3 = new File(voicepath1);
				if (file3.exists()) {
					files.add(file3);
				}
			}
			System.out.println(files.size());
			if (Tool.isNetworkAvailable(ServiceScheduleAccomplishActivity.this)) {
				if (files.size() > 0 && !files.isEmpty()) {
					count = files.size();
					params.put("fileNums", count + "");
					params.put("functionCode",
							Config.FUNCTION_REAL_REAPAIRTASKUPLOADFILE);
					params.put("repairId", task.getRepairId());
					params.put("sessionId", user.getSessionId());
					UploadService uploadService = new UploadService();

					try {
						System.out.println("result:" + result);
						result = uploadService.uploadFiles(url, params, files);
						Log.e("维修文件上传的result", result);
						System.out.println("result:" + result);
						flagstr = new JSONObject(result).getString("flag");
					} catch (JSONException e) {
						e.printStackTrace();
						Log.e("c超时", "c超时");
						mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
								"json解析出错").sendToTarget();

					} catch (Exception e) {
						e.printStackTrace();
						mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
								"上传文件超时").sendToTarget();
					}

					if (flagstr.equals("success")) {
						// 使用Map封装请求参数
						Map<String, String> map = new HashMap<String, String>();
						map.put("repairId", task.getRepairId());
						map.put("functionCode",
								Config.FUNCTION_REAL_REPAIRTASKCOMPLETE);
						map.put("solvedDescript", task.getSolvedDescript());
						if (null != task.getSolvedImage1()
								&& !task.getSolvedImage1().equals("")) {
							map.put("solvedImage1", task.getSolvedImage1());
						}

						if (null != task.getSolvedImage2()
								&& !task.getSolvedImage2().equals("")) {
							map.put("solvedImage2", task.getSolvedImage2());
						}
						if (null != task.getSolvedVoice()
								&& !task.getSolvedVoice().equals("")) {
							map.put("solvedVoice", task.getSolvedVoice());
						}

						// 定义发送请求的URL
						// 发送请求

						String response = "";
						try {
							String urlstr = Config.SERVER_URL
									+ user.getFunctionlistFromUser(
											Config.FUNCTION_REAL_REPAIRTASKCOMPLETE)
											.get(0).getFunctionUrl();
							String setsessionid = "";
							user = SingleSample.getInstance(
									ServiceScheduleAccomplishActivity.this)
									.getUser();
							if (null != user) {
								if (null != user.getSessionId()
										&& !user.getSessionId().equals("")) {
									setsessionid = user.getSessionId();
								}
							}
							response = HttpUtil.postRequestSe(urlstr, map,
									setsessionid);
							Log.e("完成维修的response", response);
							String flag = new JSONObject(response)
									.getString("flag");
							String message = new JSONObject(response)
									.getString("message");
							if (flag.equals(Config.CONNECT_SUCCESS2)) {
								mHandler.obtainMessage(
										Config.HANDLER_MSG_REPAIR_COMPELETE_SUCCESS,
										message).sendToTarget();

							} else {
								mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
										message).sendToTarget();
							}
						} catch (JsonSyntaxException e) {
							mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
									"json解析出错").sendToTarget();
							e.printStackTrace();
						} catch (Exception e) {
							e.printStackTrace();
							mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
									"获取数据出错").sendToTarget();
						}
					}

				} else {
					// 如果文件都为空
					Map<String, String> map = new HashMap<String, String>();
					map.put("repairId", task.getRepairId());
					map.put("functionCode",
							Config.FUNCTION_REAL_REPAIRTASKCOMPLETE);
					map.put("solvedDescript", task.getSolvedDescript() + "");
					if (null != task.getSolvedImage1()
							&& !task.getSolvedImage1().equals("")) {
						map.put("solvedImage1", task.getSolvedImage1());
					}

					if (null != task.getSolvedImage2()
							&& !task.getSolvedImage2().equals("")) {
						map.put("solvedImage2", task.getSolvedImage2());
					}
					if (null != task.getSolvedVoice()
							&& !task.getSolvedVoice().equals("")) {
						map.put("solvedVoice", task.getSolvedVoice());
					}

					// 定义发送请求的URL
					// 发送请求

					String response = "";
					try {
						String urlstr = Config.SERVER_URL
								+ user.getFunctionlistFromUser(
										Config.FUNCTION_REAL_REPAIRTASKCOMPLETE)
										.get(0).getFunctionUrl();
						String setsessionid = "";
						user = SingleSample.getInstance(
								ServiceScheduleAccomplishActivity.this)
								.getUser();
						if (null != user) {
							if (null != user.getSessionId()
									&& !user.getSessionId().equals("")) {
								setsessionid = user.getSessionId();
							}
						}
						response = HttpUtil.postRequestSe(urlstr, map,
								setsessionid);
						Log.e("完成维修的response", response);
						String flag = new JSONObject(response)
								.getString("flag");
						String message = new JSONObject(response)
								.getString("message");
						if (flag.equals(Config.CONNECT_SUCCESS2)) {
							mHandler.obtainMessage(
									Config.HANDLER_MSG_REPAIR_COMPELETE_SUCCESS,
									message).sendToTarget();

						} else {
							mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
									message).sendToTarget();
						}
					} catch (JsonSyntaxException e) {
						mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
								"json解析出错").sendToTarget();
						e.printStackTrace();
					} catch (Exception e) {
						e.printStackTrace();
						mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
								"上传文件出错").sendToTarget();
					}

				}
			} else {
				mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "请设置网络")
						.sendToTarget();
			}

		}

	};

	Runnable postStopRepairRun = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			postStopRepair();
		}
	};

	// 请求完成维修
	private void postStopRepair() {
		if (Tool.isNetworkAvailable(ServiceScheduleAccomplishActivity.this)) {
			try {
				
				String urlstr = Config.SERVER_URL
						+ user.getFunctionlistFromUser(
								Config.FUNCTION_REAL_REPAIRTASKSTOP).get(0)
								.getFunctionUrl();
				String result = null;
				Map<String, String> map = new HashMap<String, String>();
				map.put("functionCode", Config.FUNCTION_REAL_REPAIRTASKSTOP);
				map.put("repairId", repairId);
				result = HttpUtil.postRequestSe(urlstr, map, sessionId);
				Log.e("停止维修的result", result);
				String message = new JSONObject(result).getString("message");
				String flag = new JSONObject(result).getString("flag");
				if (flag.equals(Config.CONNECT_SUCCESS2)) {
					if (task.getStatusType_typeCode().equals(
							Config.TYPECODE_SERVE)) {
						task.setTaskState(Config.TASKSTATE_TODO); // 待处理
					} else if (task.getStatusType_typeCode().equals(
							Config.TYPECODE_REMINDE)) {
						task.setTaskState(Config.TASKSTATE_BEASKED);// 被催单
					}
					Task localtask = user.getTasksByRepairId(repairId).get(0);
					long taskid = localtask.getId();
					Task savetask = new Task();
					task.setStopflag(true);
					task.setSolvedDescript(localtask.getSolvedDescript());
					task.setSolvedImage1(localtask.getSolvedImage1());
					task.setSolvedImage2(localtask.getSolvedVoice());
					savetask = task;
					savetask.setUser(user);
					savetask.save();
					user.update(user.getId());
					if(user.deleteTaskByTaskId(taskid)){
						Log.e("停止维修","repairId任务更新成功");
					}else{
						Log.e("停止维修","repairId任务更新失败");
					}
					mHandler.obtainMessage(
							Config.HANDLER_MSG_REPAIR_STOP_SUCCESS, message)
							.sendToTarget();// 通知主线程数据发送成功

				} else {
					mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, message)
							.sendToTarget();// 通知主线程数据发送成功
				}

			} catch (Exception e) {
				mHandler.obtainMessage(Config.HANDLER_MSG_REPAIR_STOP_FAIL_2,
						message).sendToTarget();
				Log.e("ServiceScheduleActivity", "json数据获取报错");
				mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "json解析出错")
						.sendToTarget();
				e.printStackTrace();
			}

		} else {
			mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "请设置网络")
					.sendToTarget();
		}
	}

	Runnable getDataRun = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			getData();

		}
	};

	// 定义发送请求的方法
	private void getData() {
		if (Tool.isNetworkAvailable(ServiceScheduleAccomplishActivity.this)) {
			try {
			
				String url = Config.SERVER_URL
						+ user.getFunctionlistFromUser(realfunctioncode).get(0)
								.getFunctionUrl();
				String result = null;
				Map<String, String> map = new HashMap<String, String>();
				map.put("functionCode", realfunctioncode);
				map.put("repairId", repairId);
				String setsessionid = "";
				user = SingleSample.getInstance(
						ServiceScheduleAccomplishActivity.this).getUser();
				if (null != user) {
					if (null != user.getSessionId()
							&& !user.getSessionId().equals("")) {
						setsessionid = user.getSessionId();
					}
				}
				result = HttpUtil.postRequestSe(url, map, setsessionid);
				Log.e("任务想情的result2", result);
				result = result.replace("rows", "tasks");
				String total = new JSONObject(result).getString("total");
				String flag = new JSONObject(result).getString("flag");
				String rows = new JSONObject(result).getString("tasks");
				
				if (total.equals("0")) {
					mHandler.obtainMessage(Config.HANDLER_MSG_GETTASK_FAIL,
							"该任务不存在！").sendToTarget();
				} else {
					java.lang.reflect.Type type = new TypeToken<Task>() {
					}.getType();
					Gson gson = new Gson();
					JSONArray jsonArray = new JSONArray(rows);
					JSONObject jsonObject = jsonArray.getJSONObject(0);
					task = gson.fromJson(jsonObject.toString(), type);

					if(!user.isTaskExistByRepairId(repairId)){
						task = Tool.setTaskAll(functioncode, peopleType,
								task, user);
						
						if (flag.equals(Config.CONNECT_SUCCESS2)) {
							boolean flagb = false;
							String urlstr = Config.SERVER_URL
									+ user.getFunctionlistFromUser(
											Config.FUNCTION_REAL_DOWNLOADREPAIRFILE)
											.get(0).getFunctionUrl();
							map.put("sessionId", user.getSessionId());
							map.put("functionCode",
									Config.FUNCTION_REAL_DOWNLOADREPAIRFILE);
							if (null != task.getProblemImage1()
									&& !task.getProblemImage1().equals("")) {
								map.put("fileName", task.getProblemImage1());
								flagb = UploadService.downFile(urlstr,
										Config.IMAGE_PATH, map);
							}
							if (null != task.getProblemImage2()
									&& !task.getProblemImage2().equals("")) {
								map.put("fileName", task.getProblemImage2());
								flagb = UploadService.downFile(urlstr,
										Config.IMAGE_PATH, map);
							}
							if (null != task.getProblemVoice()
									&& !task.getProblemVoice().equals("")) {
								map.put("fileName", task.getProblemVoice());
								flagb = UploadService.downFile(urlstr,
										Config.VOICE_PATH, map);
							}
							if (null != task.getSolvedImage1()
									&& !task.getSolvedImage1().equals("")) {
								map.put("fileName", task.getSolvedImage1());
								flagb = UploadService.downFile(urlstr,
										Config.IMAGE_PATH, map);
							}
							if (null != task.getSolvedImage2()
									&& !task.getSolvedImage2().equals("")) {
								map.put("fileName", task.getSolvedImage2());
								flagb = UploadService.downFile(urlstr,
										Config.IMAGE_PATH, map);
							}
							if (null != task.getSolvedVoice()
									&& !task.getSolvedVoice().equals("")) {
								map.put("fileName", task.getSolvedVoice());
								flagb = UploadService.downFile(urlstr,
										Config.VOICE_PATH, map);
							}
							if (flagb) {
								mHandler.obtainMessage(
										Config.HANDLER_MSG_SUCCESS, message)
										.sendToTarget();// 通知主线程数据发送成功
							} else {
								mHandler.obtainMessage(
										Config.HANDLER_MSG_SUCCESS, message)
										.sendToTarget();// 通知主线程数据发送成功
							}

						} else {
							mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
									message).sendToTarget();// 通知主线程数据发送成功
						}
					
					}else{
						
					}
					
				}

			} catch (Exception e) {
				Log.e("ServiceScheduleActivity", "json数据获取报错");
				mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "json解析出错")
						.sendToTarget();
				e.printStackTrace();
			}

		} else {

			mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "请设置网络")
					.sendToTarget();
		}
	}

	private Runnable saveDataRun = new Runnable() {
		public void run() {
			saveData();
			if (Tool.isNetworkAvailable(ServiceScheduleAccomplishActivity.this)) {
				mHandler.obtainMessage(Config.HANDLER_MSG_LOACALSAVE_SUCCESS,
						"保存成功").sendToTarget();
			} else {
				mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "请设置网络")
						.sendToTarget();
			}

		}
	};


	private void saveData() {
		task.setSolvedImage1(solveimagePath1);
		task.setSolvedImage2(solveimagePath2);
		task.setSolvedVoice(solvevoicePath);
		task.setSolvedVoiceTime(voiceTime + "");
		task.setSolvedDescript(accomplish_servicedescribe.getText().toString());
		if (task.getStatusType_typeCode().equals(Config.TYPECODE_REMINDE)) {
			task.setTaskState(Config.TASKSTATE_BEASKED);
		} else {
			task.setTaskState(Config.TASKSTATE_TOPOST);
		}
		task.setStopflag(false);
		task.setMoreflag(true);
		task.setUser(user);
		task.update(task.getId());
		user.update(user.getId());
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) { // 监控/拦截/屏蔽返回键
			saveData();
			finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

}
